﻿using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace TrackIT.Common.Configuration
{
    public class TrackITSettings
    {
        public TrackITSettings _settings = null;
        private string _filename = @"TrackITSettings.xml";

        public TrackITSettings()
        {
            _settings = new TrackITSettings();
        }

        public void Save()
        {
            XmlSerializer ser = new XmlSerializer(typeof(TrackITSettings));
            FileStream fs = new FileStream(_filename, FileMode.Create);
            ser.Serialize(fs, _settings);
            fs.Close();
        }

        public void Load()
        {
            if (File.Exists(_filename))
            {
                XmlSerializer ser = new XmlSerializer(typeof(TrackITSettings));
                FileStream fs = new FileStream(_filename, FileMode.Open);
                XmlReader reader = new XmlTextReader(fs);
                _settings = (TrackITSettings)ser.Deserialize(reader);
                fs.Close();
            }
        }
    }

    [Serializable]
    public class Settings
    {
        public String TaskFilename { get; set; }

        public String MantisIssueNumberRegEx { get; set; }

        public String MantisServer { get; set; }

        public String ProjectId { get; set; }

        public String MantisUserName { get; set; }

        public String MantisPassword { get; set; }

        public String WorkFilename { get; set; }

        public String TaskPrefix { get; set; }

        public bool DetectWorkFileChange { get; set; }

        public bool UseMantis { get; set; }
    }
}